// We require the Hardhat Runtime Environment explicitly here. This is optional 
// but useful for running the script in a standalone fashion through `node <script>`.
//
// When running the script with `hardhat run <script>` you'll find the Hardhat
// Runtime Environment's members available in the global scope.
const hre = require("hardhat");
const BigNumber = require('bignumber.js');
const signers = {}
function getNow() {
  return parseInt(Date.now() / 1000)
}

const  baseTime  = getNow();
// const startTime = baseTime + 10000;
let startTime = 1700000000;
let endTime = 666666666666;

startTime = 0;
endTime = 18446744073709551615;

// 当前msg。sender
let owner;
// 手续费地址
let other;
// usdt token
let tokenA_address =  '0x9c061dc72c0203f643f9a348dfcce3e73b5bd2c8';
// fsn token
let tokenB_address =  '0xed0294dbd2a0e52a09c3f38a09f6e03de2c44fcf';
// pair合约
let pair_address = '0xaF9E92E7Ddc86eF98822035A93Dc3648CA687b03';
//工厂合约地址
const factory_address = "0x74aC9080Bf16D3603F6aef02dBe1Ce8806049BAd";
// 时间参数
let TIME_ARR = [0,"18446744073709551615",0,"18446744073709551615"];
// path
let TOKEN_ARR = ["0x9c061dc72c0203f643f9a348dfcce3e73b5bd2c8","0xed0294dbd2a0e52a09c3f38a09f6e03de2c44fcf"];
;
//owner 运行前 余额
let per_owner_account_usdt = 0;
let per_owner_account_fsn = 0;
//fee 运行前 余额
let per_fee_account_usdt = 0;
let per_fee_account_fsn = 0;

async function main() {
  [owner, other] = await hre.ethers.getSigners();
  signers.address = owner.address
  signers.twoaddress = other.address;
  // console.log('owner',owner.address);
  // console.log('other',other.address);
  // console.log("Account balance:", (await owner.getBalance()).toString());

  await sleep()
  // 部署router 合约
  const uniRouter = await router(factory_address);
  await sleep()
  // 开始对 路由合约 授权
  await approve(uniRouter.address,tokenA_address)
  await approve(uniRouter.address,tokenB_address)
 
  await sleep();
  //添加池子
  //await addLiquidity(uniRouter, tokenA_address,tokenB_address)
  await sleep();

  // pair 合约给 router合约授权  因为router合约要转用户的流动性token
  const ChaingeDexPair = await hre.ethers.getContractAt("ChaingeDexFRC758", pair_address);
  await ChaingeDexPair.approve(uniRouter.address,"1000000000000000000000");

  // 开始移除流动性
  // await removeLiquidity(uniRouter, tokenA_address,tokenB_address);
  await sleep();

  // 开始swap  输入-> 输出
  // await swapExactTokensForTokens(uniRouter, tokenA_address,tokenB_address);
  await sleep();



  // 开始swap  输出-> 输入
  await swapTokensForExactTokens(uniRouter, tokenA_address,tokenB_address);
  // await feeToBalance( pair, other.address, owner)
  // await sleep()

  // await swap(uniRouter, tokenA.address, tokenB.address)

  // await checkBalance(tokenA, tokenB)

  // await feeToBalance( pair, other.address, owner, )
  
  //const lpTokenBalance = await feeToBalance( pair, other.address, owner, )
  // await approve(uniRouter.address,pair)
  // await tokenA.approve(routerAddress, '10000000000000000000000000000000000')

  // console.log(lpTokenBalance);
  // await feeToRemoveLiquidity(uniRouter, tokenA.address, tokenB.address, lpTokenBalance, 0, 0, other.address);

  // const bal3 = await tokenA.timeBalanceOf(other.address, 1619395996, endTime); 
  // const bal4 = await tokenB.timeBalanceOf(other.address, 1619395996, endTime); 
  // console.log('feeTo 取出来的A', bal3 )
  // console.log('feeTo 取出来的B', bal4 )

  // 再次充值LP， 切分LPTOken 再 用半段的到期后的LPTOKEN取回自己的流动性。


  // await  frc758Test();
  // at  合约
  // const UniswapV2Router02 = await hre.ethers.getContractFactory("UniswapV2Router02");
  // const UniswapV2Router02 = await Greeter.deploy("0xfabb0ac9d68b0b445fb7357272ff202c5651694a");
  // await uniswapV2Router02.deployed();
  // console.log("Greeter deployed to:", uniswapV2Router02.address);
  // 部署 token 合约
  // const {toeknA, toeknB} = await depErc20()
  // const {tokenA, tokenB} = await frc758()
  // 部署工厂合约
  // const {uniswapV2Factory} = await factory(owner.address, other.address)
  // const pair =  await createPair(uniswapV2Factory, tokenA, tokenB)
}

// We recommend this pattern to be able to use async/await everywhere
// and properly handle errors.
main()
  .then(() => process.exit(0))
  .catch(error => {
    console.error(error);
    process.exit(1);
  });


async function sleep() {
  return new Promise(function(res, rej) {
      setTimeout(() => {
          res()
      }, 0)
  })
}

async function depErc20() {
  const TokenERC20 = await hre.ethers.getContractFactory("TokenERC20");
  const tokenA = await TokenERC20.deploy(18, "TokenA", "TOA");
  await tokenA.deployed();
  await sleep()
  console.log('tokenA address', tokenA.address);
  await tokenA.mint(18000000000)
  await sleep()
  const tokenB = await TokenERC20.deploy(18, "TokenB", "TOB");
  await tokenB.deployed();
  await sleep()
  await tokenB.mint(18000000000)
  console.log('toeknB address', tokenB.address)

  return {
    tokenA,
    tokenB
  }
}

async function frc758() {
  const FRC758 = await hre.ethers.getContractFactory("ChaingeToken");
  const tokenA = await FRC758.deploy("TokenA", "F1", 10,10000);
  await tokenA.deployed();
  await sleep()

  console.log( await tokenA.name())
  // console.log( tokenA.balanceOf)

  console.log('tokenA address', tokenA.address);

  await tokenA.mint(signers.address , "100000")

  const bal = await tokenA.balanceOf(signers.address); // startTime 必须大于当前时间

  console.log('tokenA balance:', parseInt(bal._hex))
  // console.log(msg.sender, balance0, tokenA);
  await sleep()
  const tokenB = await FRC758.deploy("TokenB", "F2", 6,10000);
  await tokenB.deployed();
  await sleep()

  await tokenB.mint(signers.address, "200000")
  console.log('toeknB address', tokenB.address)
  const bal2 = await tokenB.balanceOf(signers.address); // startTime 必须大于当前时间
  console.log('tokenB balance:', parseInt(bal2._hex))

  return {
    tokenA,
    tokenB
  }
}


async function frc758Test() {
  const FRC758 = await hre.ethers.getContractFactory("ChaingeToken");
  const tokenA = await FRC758.deploy("TokenA", "F1", 10,10000);
  await tokenA.deployed();
  await sleep()

  console.log( await tokenA.name())
  console.log('tokenA address', tokenA.address);

  await tokenA.mintTimeSlice(signers.address , "10000",1700000000,666666666666);
  const bal = await tokenA.timeBalanceOf(signers.address,1700000000,666666666666); // startTime 必须大于当前时间
  console.log('tokenA balance:','mint 后', parseInt(bal._hex))

  await tokenA.timeSliceTransferFrom(signers.address,signers.twoaddress,2000,1700000000,666666666666);
  const bal_two = await tokenA.balanceOf(signers.address); // startTime 必须大于当前时间
  console.log('tokenA balance:','timeSliceTransferFrom 后', parseInt(bal_two._hex))

  const bal_orther_two = await tokenA.timeBalanceOf(signers.twoaddress,1700000000,666666666666); // startTime 必须大于当前时间
  console.log('tokenA  bal_orther_two balance:','timeSliceTransferFrom 后', parseInt(bal_orther_two._hex),signers.twoaddress)

  // await tokenA.timeSliceTransferFrom(signers.twoaddress,signers.address,2000,startTime,endTime);

  // const bal_three = await tokenA.balanceOf(signers.address); // startTime 必须大于当前时间
  // console.log('tokenA balance:','two timeSliceTransferFrom 后', parseInt(bal_three._hex))

}

async function factory(addr, otherAddress) {
  console.log('start ChaingeDexFactory')
  const UniswapV2Factory = await hre.ethers.getContractFactory("ChaingeDexFactory");
  const uniswapV2Factory = await UniswapV2Factory.deploy(addr);
  await uniswapV2Factory.deployed();
  console.log('end uniswapV2Factory')
  await sleep()
  
  await uniswapV2Factory.setFeeTo(otherAddress);

  return {
    uniswapV2Factory: uniswapV2Factory
  }
}

async function createPair(factory, tokenA, tokenB) {
  console.log('start createPair')
  await factory.createPair(tokenA.address, tokenB.address, [ startTime,endTime, startTime,endTime]); // 创建个1617212453 到永远的和 1627212453 到永远的。
  let pair = await factory.getPair(tokenA.address, tokenB.address, [ startTime,endTime, startTime,endTime]);
  console.log('end createPair',pair)
  return pair
}

async function router (factory) {
  // 路由合约
  const Router = await hre.ethers.getContractFactory("ChaingeSwap");
  const _factory = factory;
  const _adminAddress = owner.address;
  const _feeAddress = other.address;
  const _swapFee = 3;
  const _addLiquidityFee = 3;
  const _removeLiquidityFee = 3;
  const uniRouter = await Router.deploy(_factory,_adminAddress,_feeAddress,_swapFee,_addLiquidityFee,_removeLiquidityFee);
  await uniRouter.deployed();
  console.log("路由合约地址:", uniRouter.address);
  return uniRouter
}

async function approve(contractAddress, token) {
  console.log("approve start to router");
  const tokenContract = await hre.ethers.getContractAt("ChaingeToken", token);
  // 给路由合约授权
  await tokenContract.approve(contractAddress, '10000000000000000000000000000000000')
  // console.log("approve end");
}

//获取tokenA 和 tokenB 的 添加比例
async function getAmountsOut(uniRouter, addressA, addressB) {
  let tokenAinput  = "10000000";
  let path = [addressA,addressB];
  let outsAb = await uniRouter.getAmountsOut(tokenAinput,path,TIME_ARR);
  // console.log("getAmountsOut获取的比例为",outsAb);
  return outsAb;
}


//获取tokenB 和 tokenA 的 添加比例
async function getAmountsIn(uniRouter, addressA, addressB) {
  let tokenAinput  = "79507794641270200000";
  let path = [addressB,addressA];
  let outsAb = await uniRouter.getAmountsIn(tokenAinput,path,TIME_ARR);
  // console.log("getAmountsIn获取的比例为",outsAb);
  return outsAb;
}


//添加池子
async function addLiquidity(uniRouter, addressA, addressB) {
  //添加钱检查余额
  await addPreCheckAount(addressA,addressB);
  console.log("开始调用 addLiquidity");
  // const now = getNow() + 400;
  let amountsOut = await getAmountsOut(uniRouter, addressA, addressB);
  let amountA = parseInt(amountsOut[0]).toString();
  let minAmountA = amountA * 0.4;
  minAmountA = minAmountA.toString();
  let amountB = parseInt(amountsOut[1]).toString();
  let minAmountB = amountB * 0.4;
  minAmountB = minAmountB.toString();
  console.log({amountA,amountB,minAmountA,minAmountB,to:owner.address});
  const res = await uniRouter.addLiquidity(
    addressA,
    addressB,
    amountA,
    amountB,
    minAmountA,
    minAmountB,
    owner.address,
    9999999999999,
    TIME_ARR
  )
  console.log('addLiquidity 完成');
  // console.log(JSON.stringify(res));
  //添加后检测余额
  await addAfterCheckAount(addressA,addressB,amountA,amountB);
  return res;
}


// 添加前 池子检测账户
async function addPreCheckAount(addressA,addressB){
    const tokenAContract = await hre.ethers.getContractAt("ChaingeToken", addressA);
    const tokenBContract = await hre.ethers.getContractAt("ChaingeToken", addressB);
    let balanceA = await tokenAContract.balanceOf(owner.address);
    let balanceB = await tokenBContract.balanceOf(owner.address);
    // console.log('owner','usdt 和 fsn ',parseInt(balanceA._hex), parseInt(balanceB._hex));
    let feeBalanceA = await tokenAContract.balanceOf(other.address);
    let feeBalanceB = await tokenBContract.balanceOf(other.address);
    // console.log('fee','usdt 和 fsn ',parseInt(feeBalanceA._hex), parseInt(feeBalanceB._hex));
    //owner 运行前 余额
    per_owner_account_usdt = parseInt(balanceA._hex);
    per_owner_account_fsn =  parseInt(balanceB._hex);
    //fee 运行前 余额
    per_fee_account_usdt = parseInt(feeBalanceA._hex);
    per_fee_account_fsn  = parseInt(feeBalanceB._hex);
    console.log("addLiquidity 调用前的余额:");
    console.log({per_owner_account_usdt,per_owner_account_fsn,per_fee_account_usdt,per_fee_account_fsn});
}


// 添加后 池子检测账户
async function addAfterCheckAount(addressA,addressB,amountA,amountB){
  const tokenAContract = await hre.ethers.getContractAt("ChaingeToken", addressA);
  const tokenBContract = await hre.ethers.getContractAt("ChaingeToken", addressB);
  let balanceA = await tokenAContract.balanceOf(owner.address);
  balanceA = parseInt(balanceA._hex);
  let balanceB = await tokenBContract.balanceOf(owner.address);
  balanceB = parseInt(balanceB._hex);
  // console.log('owner','usdt 和 fsn ',parseInt(balanceA._hex), parseInt(balanceB._hex));
  let feeBalanceA = await tokenAContract.balanceOf(other.address);
  feeBalanceA = parseInt(feeBalanceA._hex);
  let feeBalanceB = await tokenBContract.balanceOf(other.address);
  feeBalanceB = parseInt(feeBalanceB._hex);
  // console.log('fee','usdt 和 fsn ',parseInt(feeBalanceA._hex), parseInt(feeBalanceB._hex));

  // usdt 减少的 数量
  let diffUsdt = new BigNumber(per_owner_account_usdt).minus(balanceA).toNumber();
  // usdt 减少的 数量 * 3/10000  手续费的数量
  let feeUsdtPoint =  new BigNumber(amountA).times(3/10000).toNumber();
  // 实际收到的usdt fee 的数量
  let feeUsdt = new BigNumber(feeBalanceA).minus(per_fee_account_usdt).toNumber();  

  console.log("addLiquidity 调用后 的余额:");
  console.log({diffUsdt,feeUsdtPoint,feeUsdt});

  // fsn 减少的 数量
  let diffFsn = new BigNumber(per_owner_account_fsn).minus(balanceB).toNumber();
  // fsn 减少的 数量 * 3/10000  手续费的数量
  let feeFsnPoint =  new BigNumber(amountB).times(3/10000).toNumber();
  // 实际收到的usdt fee 的数量
  let feeFsn = new BigNumber(feeBalanceB).minus(per_fee_account_fsn).toNumber();  

  console.log({diffFsn,feeFsnPoint,feeFsn});
  
  // //owner 运行前 余额
  per_owner_account_usdt = balanceA;
  per_owner_account_fsn =  balanceB;
  //fee 运行前 余额
  per_fee_account_usdt = feeBalanceA;
  per_fee_account_fsn  = feeBalanceB;
  console.log({per_owner_account_usdt,per_owner_account_fsn,per_fee_account_usdt,per_fee_account_fsn});
}



// 添加后 池子检测账户
async function removeAfterCheckAount(addressA,addressB){
  const pairContract = await hre.ethers.getContractAt("ChaingeToken", pair_address);
  let balancePair = await pairContract.balanceOf(owner.address);
  console.log("balancePair",balancePair);
  const tokenAContract = await hre.ethers.getContractAt("ChaingeToken", addressA);
  const tokenBContract = await hre.ethers.getContractAt("ChaingeToken", addressB);
  let balanceA = await tokenAContract.balanceOf(owner.address);
  balanceA = parseInt(balanceA._hex);
  let balanceB = await tokenBContract.balanceOf(owner.address);
  balanceB = parseInt(balanceB._hex);
  // console.log('owner','usdt 和 fsn ',parseInt(balanceA._hex), parseInt(balanceB._hex));
  let feeBalanceA = await tokenAContract.balanceOf(other.address);
  feeBalanceA = parseInt(feeBalanceA._hex);
  let feeBalanceB = await tokenBContract.balanceOf(other.address);
  feeBalanceB = parseInt(feeBalanceB._hex);
  // console.log('fee','usdt 和 fsn ',parseInt(feeBalanceA._hex), parseInt(feeBalanceB._hex));

  // usdt 减少的 数量
  let diffUsdt = new BigNumber(per_owner_account_usdt).minus(balanceA).toNumber();
  // usdt 减少的 数量 * 3/10000  手续费的数量
  let feeUsdtPoint =  new BigNumber(diffUsdt).times(3/10000).toNumber();
  // 实际收到的usdt fee 的数量
  let feeUsdt = new BigNumber(feeBalanceA).minus(per_fee_account_usdt).toNumber();  

  console.log("removeLiquidity 调用后 的余额:");
  console.log({diffUsdt,feeUsdtPoint,feeUsdt});

  // fsn 减少的 数量
  let diffFsn = new BigNumber(per_owner_account_fsn).minus(balanceB).toNumber();
  // fsn 减少的 数量 * 3/10000  手续费的数量
  let feeFsnPoint =  new BigNumber(diffFsn).times(3/10000).toNumber();
  // 实际收到的usdt fee 的数量
  let feeFsn = new BigNumber(feeBalanceB).minus(per_fee_account_fsn).toNumber();  

  console.log({diffFsn,feeFsnPoint,feeFsn});
  
  //owner 运行前 余额
  per_owner_account_usdt = balanceA;
  per_owner_account_fsn =  balanceB;
  //fee 运行前 余额
  per_fee_account_usdt = feeBalanceA;
  per_fee_account_fsn  = feeBalanceB;
  console.log({per_owner_account_usdt,per_owner_account_fsn,per_fee_account_usdt,per_fee_account_fsn});
}



// swap后 池子检测账户
async function swapAfterCheckAount(addressA,addressB,type="atob"){
  const tokenAContract = await hre.ethers.getContractAt("ChaingeToken", addressA);
  const tokenBContract = await hre.ethers.getContractAt("ChaingeToken", addressB);
  let balanceA = await tokenAContract.balanceOf(owner.address);
  balanceA = parseInt(balanceA._hex);
  let balanceB = await tokenBContract.balanceOf(owner.address);
  balanceB = parseInt(balanceB._hex);
  // console.log('owner','usdt 和 fsn ',parseInt(balanceA._hex), parseInt(balanceB._hex));
  let feeBalanceA = await tokenAContract.balanceOf(other.address);
  feeBalanceA = parseInt(feeBalanceA._hex);
  let feeBalanceB = await tokenBContract.balanceOf(other.address);
  feeBalanceB = parseInt(feeBalanceB._hex);
  // console.log('fee','usdt 和 fsn ',parseInt(feeBalanceA._hex), parseInt(feeBalanceB._hex));

   // usdt 减少的 数量
   let diffUsdt = new BigNumber(balanceA).minus(per_owner_account_usdt).toNumber();
   // usdt 减少的 数量 * 3/10000  手续费的数量
   let feeUsdtPoint =  new BigNumber(diffUsdt).times(3/10000).toNumber();
   // 实际收到的usdt fee 的数量
   let feeUsdt = new BigNumber(feeBalanceA).minus(per_fee_account_usdt).toNumber();  

   console.log("swap 调用后 的余额:");
   console.log({diffUsdt,feeUsdtPoint,feeUsdt});

   // fsn 增加的的 数量
   let diffFsn = new BigNumber(balanceB).minus(per_owner_account_fsn).toNumber();
   // fsn 减少的 数量 * 3/10000  手续费的数量
   let feeFsnPoint =  new BigNumber(diffFsn).times(3/10000).toNumber();
   // 实际收到的usdt fee 的数量
   let feeFsn = new BigNumber(feeBalanceB).minus(per_fee_account_fsn).toNumber();  

   console.log({diffFsn,feeFsnPoint,feeFsn});
  // if(type == 'atob'){
     
  // }else{
  //     // usdt 增加的 数量
  //     let diffUsdt = new BigNumber(balanceA).minus(per_owner_account_usdt).toNumber();
  //     // usdt 减少的 数量 * 3/10000  手续费的数量
  //     let feeUsdtPoint =  new BigNumber(diffUsdt).times(3/10000).toNumber();
  //     // 实际收到的usdt fee 的数量
  //     let feeUsdt = new BigNumber(feeBalanceA).minus(per_fee_account_usdt).toNumber();  

  //     console.log("swap 调用后 的余额:");
  //     console.log({diffUsdt,feeUsdtPoint,feeUsdt});

  //     // fsn 减少的 数量
  //     let diffFsn = new BigNumber(balanceB).minus(per_owner_account_fsn).toNumber();
  //     // fsn 减少的 数量 * 3/10000  手续费的数量
  //     let feeFsnPoint =  new BigNumber(diffFsn).times(3/10000).toNumber();
  //     // 实际收到的usdt fee 的数量
  //     let feeFsn = new BigNumber(feeBalanceB).minus(per_fee_account_fsn).toNumber();  

  //     console.log({diffFsn,feeFsnPoint,feeFsn});
  // }

  //owner 运行前 余额
  per_owner_account_usdt = balanceA;
  per_owner_account_fsn =  balanceB;
  //fee 运行前 余额
  per_fee_account_usdt = feeBalanceA;
  per_fee_account_fsn  = feeBalanceB;
  console.log({per_owner_account_usdt,per_owner_account_fsn,per_fee_account_usdt,per_fee_account_fsn});
}

/*
  address tokenA,
  address tokenB,
  uint liquidity,
  uint amountAMin,
  uint amountBMin,
  address to,
  uint deadline
*/ 
async function removeLiquidity(uniRoute, addressA, addressB) {
  const pairContract = await hre.ethers.getContractAt("ChaingeToken", pair_address);
  let balancePair = await pairContract.balanceOf(owner.address);
  balancePair = balancePair.toString();
  console.log('removeLiquidity start')
  console.log({addressA,addressB,liquidity:balancePair,amountAMin:1000,amountBMin:2000,to:owner.address});
  await uniRoute.removeLiquidity(
    addressA,
    addressB,
    balancePair,
    "1000",
    "2000",
    owner.address,
    9999999999999,
    TIME_ARR
  )
  console.log('removeLiquidity success')
  await removeAfterCheckAount(addressA,addressB);
}

// 输入 -> 输出
async function swapExactTokensForTokens(uniRouter, addressA, addressB) {
  await addPreCheckAount(addressA, addressB);
  console.log('开始swap->swapExactTokensForTokens A换B');
  let amountsOut = await getAmountsOut(uniRouter, addressA, addressB);
  let amountIn = parseInt(amountsOut[0]).toString();
  let amountOutMin = (parseInt(amountsOut[1]) * 0.4).toString();
  let path = [addressA,addressB];

  await uniRouter.swapExactTokensForTokens(
    amountIn,
    amountOutMin,
    path,
    owner.address,
    999999999999,
    TIME_ARR
  )
  console.log('完成了swapExactTokensForTokens');
  await swapAfterCheckAount(addressA, addressB);
}

// 输出 -> 输入
async function swapTokensForExactTokens(uniRouter, addressA, addressB) {
  await addPreCheckAount(addressA, addressB);
  console.log('开始swap->swapTokensForExactTokens  B换A');
  let amountsIn = await getAmountsIn(uniRouter, addressA, addressB);
  let amountOut = parseInt(amountsIn[1]).toString();
  let amountInMax = parseInt((parseInt(amountsIn[0]) * 1.4)).toString();
  let path = [addressA,addressB];
  await uniRouter.swapTokensForExactTokens(
    amountOut,
    amountInMax,
    path,
    owner.address,
    999999999999,
    TIME_ARR
  )
  console.log('完成了swapExactTokensForTokens');
  await swapAfterCheckAount(addressA, addressB);
}

async function checkBalance(tokenA, tokenB) {
  const now = getNow() + 500;
  const balanceA = await tokenA.balanceOf(signers.address)
  const balanceB = await tokenB.balanceOf(signers.address)
  console.log('然后A 和 B ',parseInt(balanceA._hex), parseInt(balanceB._hex));
}

async function feeToBalance(pair ,feeToAddress, signersAddress) {
   console.log('feeToAddress', feeToAddress)
   const pairObj = await hre.ethers.getContractAt('ChaingeDexPair', pair, signersAddress)
   const otherBalance = await pairObj.timeBalanceOf(feeToAddress, startTime, endTime)
   console.log('feeToBalance ',parseInt(otherBalance._hex));
   const signersBalance = await pairObj.timeBalanceOf(signersAddress.address, startTime, endTime)
   console.log('signersAddress有多少流动性代币 ',parseInt(signersBalance._hex));

  return parseInt(otherBalance._hex)
}

async function feeToRemoveLiquidity(uniRoute, addressA, addressB, liquidity, amountAMin, amountBMin, to) {
  console.log('feeTo 开始取钱', liquidity, amountAMin, amountBMin, to)
  const now = getNow() + 500;
  await uniRoute.removeLiquidity(
    addressA,
    addressB,
    liquidity,
    amountAMin,
    amountBMin,
    to,
    9999999999999,
    [startTime, endTime, startTime, endTime]
  )
  console.log('removeLiquidity success')
}
